package com.brayan.melinxa.gui.dialogs;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Component;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.CardLayout;
import javax.swing.Box;

public class AboutDialog extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public AboutDialog() {
		setResizable(false);
		setTitle("Melinxa Mirror - About");
		getContentPane().setBackground(Color.WHITE);
		setBounds(100, 100, 505, 457);
		getContentPane().setLayout(new BorderLayout());
		{
			JPanel panel = new JPanel();
			panel.setBackground(Color.WHITE);
			getContentPane().add(panel, BorderLayout.CENTER);
			GridBagLayout gbl_panel = new GridBagLayout();
			gbl_panel.columnWidths = new int[]{0, 0, 483, 0, 0};
			gbl_panel.rowHeights = new int[]{203, 100, 0, 0};
			gbl_panel.columnWeights = new double[]{1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
			gbl_panel.rowWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE};
			panel.setLayout(gbl_panel);
			JLabel lblImage = new JLabel("");
			GridBagConstraints gbc_lblImage = new GridBagConstraints();
			gbc_lblImage.fill = GridBagConstraints.BOTH;
			gbc_lblImage.gridwidth = 4;
			gbc_lblImage.insets = new Insets(0, 0, 5, 0);
			gbc_lblImage.gridx = 0;
			gbc_lblImage.gridy = 0;
			panel.add(lblImage, gbc_lblImage);
			lblImage.setAlignmentY(Component.TOP_ALIGNMENT);
			lblImage.setVerticalAlignment(SwingConstants.TOP);
			lblImage.setHorizontalAlignment(SwingConstants.LEFT);
			lblImage.setBackground(Color.WHITE);
			lblImage.setIcon(new ImageIcon(AboutDialog.class.getResource("/media/LogoAbout.png")));
			
			Component horizontalStrut = Box.createHorizontalStrut(20);
			GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
			gbc_horizontalStrut.insets = new Insets(0, 0, 5, 5);
			gbc_horizontalStrut.gridx = 1;
			gbc_horizontalStrut.gridy = 1;
			panel.add(horizontalStrut, gbc_horizontalStrut);
			{
				JTextPane txtpnAboutText = new JTextPane();
				GridBagConstraints gbc_txtpnAboutText = new GridBagConstraints();
				gbc_txtpnAboutText.anchor = GridBagConstraints.NORTH;
				gbc_txtpnAboutText.fill = GridBagConstraints.HORIZONTAL;
				gbc_txtpnAboutText.insets = new Insets(0, 0, 5, 5);
				gbc_txtpnAboutText.gridx = 2;
				gbc_txtpnAboutText.gridy = 1;
				panel.add(txtpnAboutText, gbc_txtpnAboutText);
				txtpnAboutText.setContentType("text/html");
				txtpnAboutText
						.setText("<strong>A simple unidirectional data shadowing tool</strong>\r\n\r\n<p/>\r\n\r\nMelinxa shadows (mirrors) data in a lazy and resource-cautious approach. The source directory sends and deletes data-delta to a previously selected target - never the other way around. It is uni-directional.");
				txtpnAboutText.setEditable(false);
			}
			
			Component horizontalStrut_1 = Box.createHorizontalStrut(20);
			GridBagConstraints gbc_horizontalStrut_1 = new GridBagConstraints();
			gbc_horizontalStrut_1.insets = new Insets(0, 0, 5, 0);
			gbc_horizontalStrut_1.gridx = 3;
			gbc_horizontalStrut_1.gridy = 1;
			panel.add(horizontalStrut_1, gbc_horizontalStrut_1);
			{
				JTextPane txtpnAuthor = new JTextPane();
				GridBagConstraints gbc_txtpnAuthor = new GridBagConstraints();
				gbc_txtpnAuthor.anchor = GridBagConstraints.SOUTH;
				gbc_txtpnAuthor.fill = GridBagConstraints.HORIZONTAL;
				gbc_txtpnAuthor.insets = new Insets(0, 0, 0, 5);
				gbc_txtpnAuthor.gridx = 2;
				gbc_txtpnAuthor.gridy = 2;
				panel.add(txtpnAuthor, gbc_txtpnAuthor);
				txtpnAuthor.setContentType("text/html");
				txtpnAuthor
						.setText("\r\n&copy; 2013, Brayan Zimmerli<br>\r\nwww.brayan.com, Switzerland<br>\r\nVersion 1.0.2\r\n");
				txtpnAuthor.setFont(getFont());
				txtpnAuthor.setEditable(false);
			}
			this.repaint();
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setBackground(Color.WHITE);
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.Y_AXIS));
			{
				JPanel panel = new JPanel();
				panel.setBackground(Color.WHITE);
				buttonPane.add(panel);
				panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
				
				JSeparator separator = new JSeparator();
				panel.add(separator);
			}
			{
				JPanel panel = new JPanel();
				panel.setBackground(Color.WHITE);
				FlowLayout flowLayout = (FlowLayout) panel.getLayout();
				flowLayout.setAlignment(FlowLayout.RIGHT);
				buttonPane.add(panel);
				JButton okButton = new JButton("OK");
				panel.add(okButton);
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						closeDialog();
					}
				});
				okButton.setActionCommand("OK");
				getRootPane().setDefaultButton(okButton);
			}
		}
	}

	private void closeDialog() {
		this.dispose();
	}
}
